package com.xiaohei.EE_IBATIC_Demo.dao.ibatis;

import java.util.List;
import java.util.Set;

import com.ibatis.dao.client.DaoManager;
import com.ibatis.dao.client.template.SqlMapDaoTemplate;
import com.xiaohei.EE_IBATIC_Demo.dao.IDeptDao;
import com.xiaohei.EE_IBATIC_Demo.model.Department;
import com.xiaohei.EE_IBATIC_Demo.model.PageQuery;

public class DeptDaoImpl extends SqlMapDaoTemplate implements IDeptDao {

	public DeptDaoImpl(DaoManager manager) {
		super(manager);
	}
	public boolean addDept(Department d) {
		boolean b = this.checkIfDeptExist(d.getDept_id());
		if(b==true)
		this.insert("insertDept", d);
		return b;
	}
	public Integer deleteDept(String id) {
		return this.delete("deleteDeptById", id);
	}
	public Integer updateDept(Department d) {
		Integer id = (Integer)this.update("updateDept", d);
		return id;
	}
	public List<Department> findAllDept() {
		List<Department> as = this.queryForList("findAllDept", Department.class);
		return as;
	}
	public List<Department> findValidDept(String deptId){
		List<Department> as = this.queryForList("findValidDept", deptId);
		return as;
	}
	public List<Department> findAllDeptByPage(PageQuery p) {
		List<Department> as = this.queryForList("findAllDeptByPage",p);
		return as;
	}
	public Integer getPageCount(){
		Integer i = (Integer) this.queryForObject("getPageCount",java.lang.Integer.class );
		return i;
	}
	public boolean checkIfDeptExist(String d_id){
		boolean b = false;
		Integer i = (Integer) this.queryForObject("checkIfDeptExist",d_id);
		if(i==0){
			b=true;
		}
		return b;
	}
	
}
